﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PBOffice.Models;
using System.Data;
using System.Data.SqlClient;

namespace PBOffice.DAL
{
  public   class UsingRecordService
    {
      public List<UsingRecord> GetAllRecordByDate(DateTime time)
      {
          List<UsingRecord> list = new List<UsingRecord>();
          string sql = string.Format("select u.*,d.* from UsingRecord u,DayTime d where u.TimeId=d.Id and u.UsingDate='{0}'", time);
          using (SqlDataReader dr = SqlHelp.ExecuteReader(SqlHelp.connectionstring, CommandType.Text, sql))
          {
              while (dr.Read())
              {
                  UsingRecord us = new UsingRecord();
                  DayTime day = new DayTime();
                  day.Id = (int)dr["Id"];
                  day.Desc = dr["Descriptions"].ToString();
                  us.RecordId = (int)dr["RecordId"];
                  us.RoomNo = dr["RoomNo"].ToString();
                  us.StfCode = dr["StfCode"].ToString();
                  us.Time = day;
                  us.UsingDate = Convert.ToDateTime(dr["UsingDate"]);
                  list.Add(us);
              }
          }
          return list;
      }
    }
}
